home *** CD-ROM | disk | FTP | other *** search
- /* modify.c Modify RMS record header for VMS file to turn a stream format
- * file into a fixed-length blksiz-byte format files.
- *
- * Programmer: R. White Date: 22 April 1992
- */
- #include <stdio.h>
- #include <file.h>
-
- static void modify();
-
- static void
- usage()
- {
- fprintf(stderr, "Usage: MODIFY filename [ blksize ]\n");
- exit(-1);
- }
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- int arg = 0;
- char *filename;
- int blksiz;
-
- if (++arg >= argc) usage();
- filename = argv[arg];
- if (++arg < argc) {
- if (sscanf(argv[arg], "%d", &blksiz) != 1) {
- fprintf(stderr, "modify: bad blksize %s\n", argv[arg]);
- usage();
- }
- } else {
- blksiz = 512;
- }
- if (++arg < argc) {
- fprintf(stderr, "modify: too many parameters %s...\n", argv[arg]);
- usage();
- }
- modify(filename, blksiz);
- exit(0);
- }
-
- /* Procedure which changes record format to fixed and record
- * length to blksiz (parameter) for file filename (parameter)
- * by modifying file header.
- *
- * As written by C, the file has the following attributes:
- *
- * Record format: Stream_LF
- * Record attributes: Carriage return carriage control
- *
- * After being modified, it has:
- *
- * Record format: Fixed length <blksiz> byte records
- * Record attributes: None
- *
- * The binary contents of the file are just fine for fixed length records
- * (i.e. there's no extra junk between records). It's convenient to write
- * the file in the default Stream_LF format, though, because then I don't
- * have to break up all the records into <blksiz>-byte chunks.
- *
- * Created from a program from Pittsburgh Supercomputer Center.
- *
- * Programmer: R. White Date: 1 April 1988
- */
-
- #include <fab.h>
- #define RME$C_SETRFM 0X00000001
-
- static void
- modify(filename, blksiz)
- char *filename;
- long blksiz;
- {
- struct FAB myfab = cc$rms_fab;
- long status;
-
- if (blksiz < 1 || blksiz > 32767) {
- fprintf(stderr,
- "modify: blocksize must be between 1 and 32767 inclusive.");
- exit(1);
- }
-
- myfab.fab$b_fac = FAB$M_PUT; /* file access mode = put access */
- myfab.fab$l_fop |= FAB$M_ESC; /* escape to allow $modify */
- myfab.fab$l_ctx |= RME$C_SETRFM; /* user context (whatever that is) */
- myfab.fab$w_ifi = 0; /* internal file identifier */
-
- myfab.fab$l_fna = filename; /* filename */
- myfab.fab$b_fns = strlen(filename); /* filename length */
-
- if (((status = SYS$OPEN(&myfab, 0, 0)) & 7) != 1) {
- fprintf(stderr,"modify: Couldn't open %s\n", filename);
- exit(status);
- }
-
- myfab.fab$w_mrs = blksiz; /* record length */
- myfab.fab$b_rfm = FAB$C_FIX; /* fixed record format */
-
- if (((status = SYS$MODIFY(&myfab, 0, 0)) & 7) != 1) {
- fprintf(stderr,"modify: Couldn't modify %s\n", filename);
- exit(status);
- }
-
- if (((status = SYS$CLOSE(&myfab, 0, 0)) & 7) != 1) {
- fprintf(stderr,"modify: Couldn't close %s\n", filename);
- exit(status);
- }
- }
-